package bancos;

import conexion.CConexion;
import utilitario.CNumeros;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class CBacq022 extends CConexion {

    private String compania = null;
    private CNumeros numero = new CNumeros();

    public CBacq022() {
        super();
        compania = login.getCompaniaActual();
    }

    public void anulacion(String coba, String ctab, String valo) throws SQLException {
        String sqlAnulacion = "select * from bacq022 where bacq022nocia = '" + compania + "' and bacq022coba = '" + coba + "' and bacq022ctab = '" + ctab + "'";
        Statement stncAnulacion = this.getConexion().createStatement();
        ResultSet rsAnulacion = stncAnulacion.executeQuery(sqlAnulacion);
        rsAnulacion.next();
        double smac = rsAnulacion.getDouble("bacq022smac");
        double valor = Double.parseDouble(valo);
        smac += valor;
        rsAnulacion.close();
        stncAnulacion.close();
        String sqlUpAnulacion = "update bacq022 set bacq022smac = '" + numero.formatearDecimales(2, smac) + "' where bacq022nocia = '" + compania + "' and bacq022coba = '" + coba + "' and bacq022ctab = '" + ctab + "'";
        Statement stncUpAnulacion = this.getConexion().createStatement();
        stncUpAnulacion.executeUpdate(sqlUpAnulacion);
        stncUpAnulacion.close();
    }

    public void actualizar(String coba, String ctab, String ano, String mes, String valo) throws SQLException {
        String sqlBuscar = "select * from bacq022 where bacq022nocia = '" + compania + "' and bacq022coba = '" + coba + "' and bacq022ctab = '" + ctab + "'";
        Statement stncBuscar = this.getConexion().createStatement();
        ResultSet rsBuscar = stncBuscar.executeQuery(sqlBuscar);
        rsBuscar.next();
        double smac = rsBuscar.getDouble("bacq022smac");
        double valor = Double.parseDouble(valo);
        smac -= valor;
        rsBuscar.close();
        stncBuscar.close();
        String sqlActualizar = "update bacq022 set bacq022smac = '" + numero.formatearDecimales(2, smac) + "' where bacq022nocia = '" + compania + "' and bacq022coba = '" + coba + "' and bacq022ctab = '" + ctab + "'";
        Statement stncActualizar = this.getConexion().createStatement();
        stncActualizar.executeUpdate(sqlActualizar);
        stncActualizar.close();
    }
    public void actualizarAMas(String coba, String ctab, String ano, String mes, String valo) throws SQLException {
        String sqlBuscar = "select * from bacq022 where bacq022nocia = '" + compania + "' and bacq022coba = '" + coba + "' and bacq022ctab = '" + ctab + "'";
        Statement stncBuscar = this.getConexion().createStatement();
        ResultSet rsBuscar = stncBuscar.executeQuery(sqlBuscar);
        rsBuscar.next();
        double smac = rsBuscar.getDouble("bacq022smac");
        double valor = Double.parseDouble(valo);
        smac += valor;
        rsBuscar.close();
        stncBuscar.close();
        String sqlActualizar = "update bacq022 set bacq022smac = '" + numero.formatearDecimales(2, smac) + "' where bacq022nocia = '" + compania + "' and bacq022coba = '" + coba + "' and bacq022ctab = '" + ctab + "'";
        Statement stncActualizar = this.getConexion().createStatement();
        stncActualizar.executeUpdate(sqlActualizar);
        stncActualizar.close();
    }
}
